<?php

namespace App\Services\User;

use App\Exceptions\ApiExceptions;
use App\Models\UserEducationModel;
use App\Services\AbstractBaseService;

class EducationService extends AbstractBaseService
{

    /**
     * @param int $uid
     * @param string $name 学校名称
     * @param string $degree 学历
     * @param string $graduation_date 毕业时间
     * @param string $major 专业
     * @return void
     * @throws ApiExceptions
     */
    public function update(int $uid, string $name, string $degree, string $graduation_date, string $major)
    {
        $res = UserEducationModel::query()->where('user_id', $uid)->updateOrCreate(
            [
                'user_id' => $uid,
            ],
            [
                'school_name' => $name,
                'degree' => $degree,
                'graduation_date' => $graduation_date,
                'major' => $major,
            ]
        );
        if (!$res) {
            throw new ApiExceptions('更新失败');
        }
    }
}